package com.example.verifysdk;

import android.content.Context;
import android.content.SharedPreferences;

import com.example.verifysdk.compare.RegisterObjBean;
import com.example.verifysdk.creatcode.LoginObjBean;

/**
 *
 * @author LiuV
 * @date 2017/5/2
 */

public class SpHelper {
    private static final String TAG = "SpHelper";
    private static String NAME = "face_detection_sdk_";

    public static final String SDK_SECRET = "sdk_secret";
    public static final String SDK_TOKEN = "sdk_token";
    public static final String SDK_USER_ID = "sdk_user_id";
    public static final String SDK_LAST_SECRET_DATE = "sdk_last_secret_date";
    public static final String SDK_FACE_PH = "sdk_face_ph";
    private static final String PARTNER_REMARK = "_partner_remark";

    private static final String SCANNER_TOKEN = "scanner_token";
    private static final String SERVICE_HOST = "sevice_host";
    public static String mUserId = "";

    private SharedPreferences mSharedPreferences;

    public SpHelper(Context context){
        this(context, Context.MODE_PRIVATE);
    }

    private SpHelper(Context context, int mode){
        mSharedPreferences = context.getSharedPreferences(NAME, mode);
    }

    public boolean putPartenrRemark(String partenrRemark){
        SharedPreferences.Editor editor = mSharedPreferences.edit();
        editor.putString(PARTNER_REMARK, partenrRemark);
        return editor.commit();
    }

    public String getPartnerRemark(){
        return mSharedPreferences.getString(PARTNER_REMARK, "");
    }

    public String getString(String key){
        return mSharedPreferences.getString(key + getPartnerRemark(), "");
    }

    public boolean putString(String key, String value){
        SharedPreferences.Editor editor = mSharedPreferences.edit();
        editor.putString(key + getPartnerRemark(), value);
        return editor.commit();
    }

    public boolean putRegistInfo(RegisterObjBean bean){
        SharedPreferences.Editor editor = mSharedPreferences.edit();
        editor.putString(SDK_SECRET + getPartnerRemark(), bean.getSecret());
        editor.putString(SDK_TOKEN + getPartnerRemark(), bean.getToken());
        editor.putString(SDK_USER_ID + getPartnerRemark(), bean.getUserId());
        editor.putString(SDK_FACE_PH + getPartnerRemark(), bean.getFacePhoto());

        return editor.commit();
    }

    public boolean putLoginInfo(LoginObjBean bean){
        SharedPreferences.Editor editor = mSharedPreferences.edit();
        editor.putString(SDK_SECRET + getPartnerRemark(), bean.getSecret());
        editor.putString(SDK_TOKEN + getPartnerRemark(), bean.getToken());
        editor.putString(SDK_USER_ID + getPartnerRemark(), bean.getUserId());
        editor.putString(SDK_FACE_PH + getPartnerRemark(), bean.getFacePhoto());
        return editor.commit();
    }

    public String getSdkToken(){
        return mSharedPreferences.getString(SDK_TOKEN + getPartnerRemark(), "");
    }

    public String getSdkSecret(){
        return mSharedPreferences.getString(SDK_SECRET + getPartnerRemark(), "");
    }

    public String getSdkUserId(){
        return mSharedPreferences.getString(SDK_USER_ID + getPartnerRemark(), "");
    }

    public String getSdkFacePh(){
        return mSharedPreferences.getString(SDK_FACE_PH + getPartnerRemark(), "");
    }

    public boolean setScannerToken(String token){
        return putString(SCANNER_TOKEN, token);
    }

    public String getScannerToken(){
        return getString(SCANNER_TOKEN);
    }

    public boolean setServiceHost(String host){
        LogUtil.i(TAG, "---setServiceHost===" + host);
        SharedPreferences.Editor editor = mSharedPreferences.edit();
        editor.putString(SERVICE_HOST, host);
        return editor.commit();
    }

    public String getServiceHost(){
        return mSharedPreferences.getString(SERVICE_HOST, "");
    }

}
